<?php

namespace App\Api\Controllers;

use App\Api\Requests\LoginRequest;

class LoginController extends BaseController
{

    /**
     * @apiDefine login 登入类
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 登录
     * @param \App\Api\Requests\LoginRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(LoginRequest $request)
    {
        $credentials = $request->all();

        $token = auth('api')->attempt($credentials);

        if ($token == false) {
            return $this->failure("账号或密码错误");
        }
        return $this->success("登录成功", [
            'token_type'   => 'Bearer',
            'access_token' => $token,
            'expires_in'   => 86399,
        ]);
    }
}
